// http://projecteuler.net/index.php?section=problems&id=1
//
// If we list all the natural numbers below 10 that are multiples of 3
// or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
//
// Find the sum of all the multiples of 3 or 5 below 1000.

unsigned summation( unsigned n ) {
	// (n*(n+1))/2
	// (n^2+n)/2
	return (n*n+n)/2;
}

unsigned euler_p1( unsigned max ) {
	return summation((max-1)/5)*5
		+summation((max-1)/3)*3
		-summation((max-1)/15)*15; // would be doubly counted
}

unsigned euler_p1_2( unsigned max ) {
	unsigned result = 0;
	for (unsigned i = 1; i < max; i++ ) {
		if ( !(i%3) || !(i%5) ) {
			result += i;
		}
	}
	return result;
}

#include <iostream>
using namespace std;

int main( int argc, char *argv[] ) {
	cout << euler_p1(1000) << endl;
	cout << euler_p1_2(1000) << endl;
}
